package com.dengqi.mymodule.activity.fragment.tabpager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * Author: deng
 * Date: 2020/11/18
 * Description: 禁止滑动
 */
public class QViewPager extends ViewPager {

    // `false` 为禁用滑动。
    private boolean isScroll = true;

    public QViewPager(Context context) {
        super(context);
    }

    public QViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.isScroll && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return this.isScroll && super.onInterceptTouchEvent(event);
    }

    /**
     * 是否可滑动
     * @param b
     */
    public void setScroll(boolean b) {
        this.isScroll = b;
    }
}